package com.felix.algorithms.easy;

/**
 * RobotReturnToOrigin
 *
 * @author xuejinhua
 * @date 2018/9/13 16:07
 */
public class RobotReturnToOrigin {

    /**
     * Q657
     * @param source
     * @return
     */
    public static boolean solution(String source){
        char[] chars = source.toCharArray();
        int count1 = 0;
        int count2 = 0;
        for (char c : chars) {
            if (c == 'U'){
                count1++;
            }
            if (c == 'D'){
                count1--;
            }
            if (c == 'L'){
                count2++;
            }
            if (c == 'R'){
                count2--;
            }
        }
        return count1 == 0 && count2 == 0;
    }

    public static void main(String[] args) {
        String source = "UD";
        System.out.println(solution(source));
    }
}
